#ifndef __MOTOR__
#define __MOTOR__

#define MAX_SPEED         1000

#define IS_VALID_MOTOR_CHANNEL(channel) (channel >= 1 && channel <= 4)
#define IS_VALID_MOTOR_SPEED(speed)     (speed >= (-1)*(MAX_SPEED) && speed <= (MAX_SPEED))

/* Pins and PWMs assignment for motors */

#define M1_PWM_REGISTER   (TIM3->CCR1)
#define M1_PWM_PORT       GPIOC
#define M1_PWM_PIN        GPIO_Pin_6
#define M1_DIR1_PORT      GPIOC
#define M1_DIR1_PIN       GPIO_Pin_12
#define M1_DIR2_PORT      GPIOA
#define M1_DIR2_PIN       GPIO_Pin_14

#define M2_PWM_REGISTER   (TIM3->CCR3)
#define M2_PWM_PORT       GPIOC
#define M2_PWM_PIN        GPIO_Pin_8
#define M2_DIR1_PORT      GPIOC
#define M2_DIR1_PIN       GPIO_Pin_10
#define M2_DIR2_PORT      GPIOA
#define M2_DIR2_PIN       GPIO_Pin_12

#define M3_PWM_REGISTER   (TIM3->CCR2)
#define M3_PWM_PORT       GPIOC
#define M3_PWM_PIN        GPIO_Pin_7
#define M3_DIR1_PORT      GPIOC
#define M3_DIR1_PIN       GPIO_Pin_11
#define M3_DIR2_PORT      GPIOA
#define M3_DIR2_PIN       GPIO_Pin_13

#define M4_PWM_REGISTER   (TIM3->CCR4)
#define M4_PWM_PORT       GPIOC
#define M4_PWM_PIN        GPIO_Pin_9
#define M4_DIR1_PORT      GPIOA
#define M4_DIR1_PIN       GPIO_Pin_15
#define M4_DIR2_PORT      GPIOA
#define M4_DIR2_PIN       GPIO_Pin_11

/* Enable motor */
void EnableMotor(u8 channel);
/* Stop motor */
void StopMotor(u8 channel);
/* Set speed of specified motor */
int SetSpeed(u8 channel, int speed);
/* Get speed of specified motor */
int GetSpeed(u8 channel);

#define START_ADC_CHANNEL 10
#define IS_VALID_ADC_CHANNEL(channel) (channel >= 1 && channel <= 4)

/* Read ADC1 channel */
u16 readADC1(u8 channel);

#endif

